package com.itheima.arraylist;

import com.itheima.domain.Student;

import java.util.ArrayList;

public class Demo5ArrayList {
    /*
    集合数据筛选
     */
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student s1 = new Student("zhangsan",14);
        Student s2 = new Student("lisi",15);
        Student s3 = new Student("wangwu",25);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        ArrayList<Student> newList = getList(list);
        for (int i = 0; i < newList.size(); i++) {
            Student stu = newList.get(i);
            System.out.println(stu.getName()+"..."+stu.getAge());
        }
    }
    public static ArrayList<Student> getList(ArrayList<Student> list){
        ArrayList<Student> newList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            int age = stu.getAge();
            if(age < 18){
                newList.add(stu);
            }
        }
        return newList;
    }
}
